package com.wngbms.aop._03;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import java.util.Random;

//@Aspect // 删除该注解否则不生效
//@Configuration
@EnableAspectJAutoProxy // 启用该注解, 否则不生效
public class AspectJAnnotationPointcutDemo {

    public static void main(String[] args) throws InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.register(AspectJAnnotationPointcutDemo.class,
                AspectAnnotationConfig.class,
                AspectAnnotationConfig2.class);
        context.refresh();

        AspectJAnnotationPointcutDemo bean = context.getBean(AspectJAnnotationPointcutDemo.class);
        bean.exe();

        // class com.wngbms.aop._03.AspectJAnnotationPointcutDemo$$EnhancerBySpringCGLIB$$2439a964
        System.out.println(bean.getClass());
        context.close();
    }

    public void exe() {
        Random random = new Random();
        if (random.nextBoolean()) {
            throw new RuntimeException("random exp");
        }

        System.out.println("exe....");
    }

}
